"""2d vector calculations with tuples"""
from math import *
def add(v1, v2):
    """returns v1 + v2"""
    return (v1[0] + v2[0], v1[1] + v2[1])

def dif(v1, v2):
    """returns v2 - v1"""
    return (v2[0] - v1[0], v2[1] - v1[1])

def neg(v):
    """returns -v"""
    return dif(v, (0, 0))

def vmul(v1, v2):
    """returns v1 * v2"""
    return (v1[0] * v2[0] + v1[0] * v2[1], v1[1] * v2[0] + v1[1] * v2[1])

def nmul(v, n):
    """returns n * v"""
    return (v[0] * n, v[1] * n)

def sqdist(v1, v2):
    """returns the square of distance between v1 and v2"""
    return ((v2[0] - v1[0])**2 + (v2[1] - v1[1])**2)

def dist(v1, v2):
    """returns the distance between v1 and v2"""
    return sqrt(sqdist(v1, v2))

def to_p(v):
    """returns v in polars"""
    return (dist((0, 0), v), atan2(v2, v1))